//
//  FriendsInformCell.m
//  觅影
//
//  Created by  陶虹 on 16/4/13.
//  Copyright © 2016年  陶虹. All rights reserved.
//

#import "FriendsInformCell.h"

@interface FriendsInformCell ()
@property (strong, nonatomic) IBOutlet UIButton *acceptButton;
@property (strong, nonatomic) IBOutlet UIButton *rejectButton;
@property (nonatomic, strong) NSString *myUsername;
@end

@implementation FriendsInformCell

// 同意好友请求
- (IBAction)acceptButtonAction:(UIButton *)acceptButton {
    EMError *error;
    
    self.myUsername = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];

    if ([[EaseMob sharedInstance].chatManager acceptBuddyRequest:self.username error:&error] && !error) {
        NSLog(@"发送同意成功");
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)3 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
            [[EaseMob sharedInstance].chatManager asyncFetchBuddyListWithCompletion:^(NSArray *buddyList, EMError *error) {
                if (!error) {
                    NSLog(@"获取成功 --- %@", buddyList);
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"add" object:buddyList];
                    [self.delegate removeCellWithRow:_row];
                }
            } onQueue:dispatch_get_main_queue()];
        });
    }
}

// 拒绝好友请求
- (IBAction)rejectButtonAction:(UIButton *)rejectButton {
    
    EMError *error;
    if ([[EaseMob sharedInstance].chatManager rejectBuddyRequest:self.myUsername reason:[NSString stringWithFormat:@"%@拒绝加你为好友", self.myUsername] error:&error] && !error) {
        NSLog(@"发送拒绝成功");
        [self.delegate removeCellWithRow:_row];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
